<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8" />
	<title>新增菜单</title>
	<div th:replace="common/common_grid_header"></div>
	
	<style type="text/css">
		.layui-form-label{
			width: 100px;
		}
	</style>
</head>
<body>
	<div style="padding: 10px;">
		<div class="layui-form" lay-filter="example">
			<div class="layui-form-item">
				<label class="layui-form-label">菜单名称</label>
				<div class="layui-input-block">
					<input name="permissionname" autocomplete="off"
						placeholder="请输入菜单名称" lay-verify="required" class="layui-input" type="text">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">菜单权限</label>
				<div class="layui-input-block">
					<input name="permission" placeholder="例如：dept:view" autocomplete="off"
						class="layui-input" lay-verify="required" type="text">
				</div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">菜单类型——暂时没用</label>
				<div class="layui-input-block">
					<select id="" name="" >
						<option value="root" selected="selected" ></option>
						<option value="root" >根目录(root)</option>
						<option value="root" >根目录(root)</option>
					</select>
				</div>
			</div>
	
			<div class="layui-form-item">
				<label class="layui-form-label">上级菜单</label>
				<div class="layui-input-block">
					<select id="parentid" name="parentid" lay-verify="required">
						<option value="root" selected="selected" >根目录(root)</option>
					</select>
				</div>
			</div>
	
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit lay-filter="submitBtn">保存</button>
				</div>
			</div>
		</div>
	</div>
</body>
<script>
	layui.use([ 'form' ], function() {
		var form=layui.form;
		
		initSelect();//初始化下拉
		
		form.on('submit(submitBtn)',function(obj){
			$.post("/system/org/permission/save",obj.field,function(res){
				if(res.code==200){
					layer.alert(res.msg,function(){
						parent.location.reload();
					});
				}
			});
			return false;
		});
		
		function initSelect(){//初始化下拉,没有用公共方法是因为他的name名字不是text 也不像重写一个接口...
			$.getJSON('/system/org/permission/getTreeTableJson',function(res){
				var $perlist = $("#parentid");
				$.each(res.data,function(i,v){
					$perlist.append("<option value= '"+v.id+"' >"+v.permissionname+"</option>");
				});
				form.render();
			});
		}
	});
</script>
</html>